/**
 * @Description:
 * @Author 卞鹏飞 <228443632@qq.com>
 * @create 27/12/24 AM9:13
 */

import { type Component, getCurrentInstance, type ComponentInternalInstance } from 'vue'
import { isArray, isString } from 'sf-utils2'

/**
 * 如果是动态组件，返回第一个组件
 * @param comps
 */
export function resolveDynamicComps(comps: string | Component | Component[]): Component {
  if (isString(comps) && typeof comps == 'string') {
    const { proxy } = getCurrentInstance() as ComponentInternalInstance
    return proxy.$refs[comps]?.[0]
  }

  if (isArray(comps)) {
    // 是数组
    return comps?.[0]
  }
  return comps as Component
}
